Skip to content

Docs redo phase 2 - #5324

Draft
jamie-lemon wants to merge 9 commits into
mainfrom
docs-redo-phase-2
Draft

jamie-lemon wants to merge 9 commits into
mainfrom
docs-redo-phase-2

Conversation

@jamie-lemon

@jamie-lemon jamie-lemon commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Making docs manageable for LLMS ( and people )

A 2,700-line page is too long for an LLM to take in one go. This splits it by task for document.rst

The solution

document.rst holds about 113 methods and 16 attributes, the large summary table, and some example sections at the end. One solution is to turn it into a folder:

classes/document/
  index.rst           ← overview: constructor, attributes, close, the summary table (links out)
  conversion.rst      ← to_markdown, to_chunks, to_json, to_text, convert_to_pdf, get_page_text/pixmap
  pages.rst           ← load_page, pages, new/insert/delete/copy/move/select, page_xref, page_cropbox, labels, chapters/locations
  merging.rst         ← insert_pdf, insert_file + the insert_pdf examples
  saving.rst          ← save, ez_save, saveIncr, tobytes, can_save_incrementally, repair, scrub, bake, subset_fonts, rewrite_images, recolor
  metadata-toc.rst    ← metadata, set_metadata, XML metadata, get_toc/set_toc/outline items, pagemode/layout/markinfo
  forms.rst           ← is_form_pdf, need_appearances, recalculate_form, get_sigflags, (form fields)
  layers.rst          ← OCGs, OCMDs, layers, layer UI configs
  embedded-files.rst  ← embfile_*
  journalling.rst     ← journal_*, save_snapshot
  low-level.rst       ← xref_*, pdf_catalog, pdf_trailer, update_object/stream, resolve_names
  security.rst        ← authenticate, needs_pass, is_encrypted, permissions

That gives 12 pages of roughly 150–350 lines each, and each one answers a single kind of question.

Results: Splitting the Document class page

All of the Document API now lives on 12 pages in docs/classes/document/. The docs build with no new warnings: the 9 that remain were there before this change. All 792 links that point into the Document pages were checked and none are broken.

Page Lines What's on it
index.rst ~330 Overview: summary table, __init__, close, general attributes (name, is_pdf, is_dirty, is_closed, is_reflowable, is_repaired, is_fast_webaccess, version_count)
conversion.rst ~675 to_markdown/to_chunks/to_json/to_text/convert_to_pdf, plus the page-content extractors (get_page_text, search_page_for, extract_image, has_links…), the box-classes note and the image-extraction example
pages.rst ~470 Loading, adding/deleting/rearranging, page labels, EPUB chapters and locations, layout/apply_css, the EPUB location note, the structure-change note, the rotate example
merging.rst ~130 insert_pdf, insert_file, the insert_pdf examples
saving.rst ~340 save, ez_save, saveIncr, tobytes, can_save_incrementally, subset_fonts, rewrite_images, recolor, scrub, bake, repair
metadata-toc.rst ~360 Metadata, XML metadata, table of contents, resolve_names, viewer settings, the set_metadata and set_toc examples
forms.rst ~90 is_form_pdf, FormFonts, get_form_fields, recalculate_form, need_appearances, get_sigflags
layers.rst ~260 OCGs/OCMDs and layer configurations
embedded-files.rst](docs/classes/document/embedded-files.rst) ~135 embfile_*
journalling.rst ~120 journal_*, save_snapshot
low-level.rst ~260 xref objects, keys, streams, catalog, trailer
security.rst ~70 needs_pass, is_encrypted, authenticate, permissions

What changed

  • Nothing lost or duplicated: there are 134 anchors in total, which matches the original page exactly. Each method or attribute appears on exactly one page.
  • Page layout: each page starts with a summary paragraph and a link back to the overview, then subsections with one-line intros. Where a guide exists, the page links to it (the optional content, journalling and low-level recipes, and Appendix 3).
  • Moved with their content:
    • The footnotes moved to the pages that cite them.
    • The layout-mode substitutions moved to conversion.rst, the only page that uses them.
    • The pymupdf-boxclasses, document_page_boxes and json_output_structure labels are on the conversion page, so :ref: links to them still work.
  • Overview page: the line "For details on embedded files refer to Appendix 3" was removed, because the new page list and the embedded-files page now cover it.
  • Box-classes URL: the hardcoded URL inside the to_markdown code sample now points to classes/document/conversion.html#pymupdf-boxclasses.
  • Translations: the ja/ko files still hold all their strings under document/index.po. Text that moved to the 11 new pages will show in English until the translation files are regenerated and split.

Still to do

  1. llms.txt: it still has a single "Document" line. Replacing it with 12 lines, one per page with a short description, is what makes this split pay off for LLMs.
  2. Old links: links like document.html#Document.save will break. A Read the Docs redirect from classes/document.html to classes/document/index.html plus a small anchor script on the overview would forward each old anchor to its new page.

@jamie-lemon
jamie-lemon requested a review from ilgeunben December 2, 2026 00:34
@jamie-lemon
jamie-lemon marked this pull request as draft December 2, 2026 00:34

@ilgeunben ilgeunben left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — automated docs-vs-code check against the PyMuPDF 2.2 wheel (no AI).

Introduced by this PR:

  1. llms/llms.txt line 42 links to classes/document.html, which is not a page in the docs; the page is now classes/document/index.html
  2. 31 pages move to new URLs and 1 page is removed (e.g. annot.html → classes/annot.html, archive-class.html → classes/archive-class.html, batch-result.html → classes/batch-result.html, document.html (removed)). Without redirects, old links, search results and URLs that AI tools remember will 404.

Already on main, in files this PR touches (optional):

  1. classes/document-writer-class.rst – DocumentWriter.__init__: options: docs default None, code default ''
  2. llms/llms.txt line 28 links to recipes-ocr.html, which is not a page in the docs
  3. llms/llms.txt line 67 links to module.html, which is not a page in the docs

Cleanup (pages render, but worth fixing while here):

  • Not usable with pymupdf-lite (no Layout engine / pymupdf4llm) — consider a note that the full pymupdf package is needed (6): Document.to_markdown; Document.to_chunks; Document.to_json; Document.to_text; use_layout; convert_batch
  • Duplicate object descriptions — add :no-index: to all but one (1): classes/point.rst Point.__init__

(Ambiguous cross-references are left out, as you're handling them separately.)

@jamie-lemon

Copy link
Copy Markdown
Collaborator Author

@ilgeunben FYI: The redirects will all be put in place on the ReadTheDocs portal. I am keeping a list of them going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants